<layout name='layout/main' />

  <header class="am-header am-header-default">
    <div class="am-header-left am-header-nav">
    <a href="<{:U('Store/index')}>"><i class="am-header-icon am-icon-home"></i></a>
    </div>
    <h1 class="am-header-title">购物车</h1>
    <div class="am-header-right am-header-nav">
    <a href="javascript:window.history.go(-1)"><i class="am-header-icon am-icon-reply"></i></a>
      </div>
  </header>
  
    <div class="tabMenu">
      <ul>
        <li>1、购物车</li>
        <li class="active">2、确认订单</li>
        <li>3、购买成功</li>
      </ul>
    </div>
    
    <section class="accounts">    
    <form class="am-form am-form-horizontal" id="orderForm" method="post" action="<{:U('Store/save')}>">  
      <div class="infobox">
        <div class="hd">收货信息</div>
        <notempty name="address">
        <p class="address_item"><{$address['province']}> <{$address['city']}> <{$address['area']}> <{$address['address']}> <br><{$address['name']}>, <{$address['mobile']}></p>
        <input type="hidden" id="address" name="address" value="<{$address['province']}> <{$address['city']}> <{$address['area']}>, <{$address['address']}>">
        <input type="hidden" name="name" id="name" value="<{$address['name']}>">
        <input type="hidden" name="mobile" id="mobile" value="<{$address['mobile']}>">
        <else/>
        <input type="hidden" id="address" name="address" value="">
        </notempty>
        <p><a href="<{:U('Address/index')}>" class="am-btn am-btn-danger am-btn-sm">管理收货地址</a></p>
      </div>    

      <!--div class="infobox">
        <div class="hd">配送方式</div>
          <ul class="payStyle" id="peisong">  
              <volist name="dispatch" id="vo">
              <li><label><input name="payment" type="radio" data-money="<{$vo.money}>" data-free="<{$vo.freeMoney}>" value="<{$vo.name}>"><{$vo.name}>[<span><egt name="goodsMoney" value="$vo['freeMoney']">免邮<else/>￥<{$vo.money}></egt></span>]，满<{$vo.freeMoney}>免邮</label></li>
              </volist>
          </ul>
      </div-->

      <div class="infobox">
        <div class="hd">支付方式</div>
          <ul class="payStyle">                
              <li><label><input name="payType" type="radio" value="2">微信支付</label></li>
              <li><label><input name="payType" type="radio" value="1">支付宝（手机版）</label></li>
          </ul>
      </div>

      <div class="infobox">
        <div class="hd">订单详情</div>
        <table class="am-table am-table-bordered am-table-radius infoTable">
          <thead>
              <tr>
                  <th>名称</th>
                  <th width="50" class="am-text-center">数量</th>
                  <th width="50" class="am-text-center">单价</th>
              </tr>
          </thead>
          <tbody>
              <volist name="list" id="vo">
              <tr>
                  <td><{$vo.pname}><noempty name="vo.pram"><br/><{$vo.pram}></noempty></td>
                  <td class="am-text-center"><{$vo.number}></td>
                  <td class="am-text-center"><{$vo.price}></td>
              </tr>
              <input type="hidden" name="pid[]" value="<{$vo.pid}>">
              <input type="hidden" name="picname[]" value="<{$vo.picname}>">
              <input type="hidden" name="pname[]" value="<{$vo.pname}> <{$vo.pram}>">
              <input type="hidden" name="number[]" value="<{$vo.number}>">
              <input type="hidden" name="price[]" value="<{$vo.price}>">              
              <input type="hidden" name="hasBaoxian[]" value="<{$vo.hasBaoxian}>">              
              </volist>
          </tbody>
        </table>
      </div>

      

      <div class="infobox">
        <div class="hd">备注信息</div>
        <textarea rows="5" name="intr" placeholder="亲，还有什么话要对我们说"></textarea>
      </div>

      <p><button class="am-btn am-btn-danger am-btn-block" id="subBtn">提交订单</button></p>
      <input type="hidden" name="money" id="money" value="<{$goodsMoney}>">
      <input type="hidden" name="wxid" id="wxid" value="<{$_user.wxid}>">
      <input type="hidden" name="paymentMoney" id="paymentMoney" value="0">
      <input type="hidden" name="baoxian" value="<{$hasBaoxian}>">
      <input type="hidden" name="order_no" value="<{$order_no}>">      
    </form>
    </section>
<div class="footerBox">
  <div class="gooodsTotal">
    <div class="moneyLeft">商品总价：<span><{$goodsMoney}></span><!--，物流：<span id="yunfei">0</span>--></div>
    <!--div class="moneyRight">合计：<span id="totalMoney"><{$goodsMoney}></span></div-->
  </div>
</div>
<script>
$(document).ready(function() {
    //ajaxform
    var options = { 
        beforeSubmit:orderRequest,//表单验证方式
        success:orderResponse  // post-submit callback 
    }; 

    $('#orderForm').ajaxForm(options); 

    function orderResponse(responseText, statusText){
        $("#loading").hide();
        $("#subBtn").removeAttr('disabled');
        if (statusText == 'success') {
            var responseText=eval('('+responseText+')');
            if(responseText.state != 'SUCCESS'){
                responseText.message = responseText.state;
            }
            _alert(responseText.message,responseText.url);                     
        }else{
            _alert('服务器错误');
        }
    } 

    function orderRequest(){
        FormStatus = checkOrder();
        if (FormStatus){
            $("#loading").show();
            $("#subBtn").attr('disabled',"true");
        }
        return FormStatus;
    }
});

$(function(){  

  _alert('温馨提示<br/>如果选购商品发生退货情况，即视为商品交易自动取消，相关赠品随交易自动取消不再赠送，销售佣金随交易自动取消不再返还。');
  
  $("#peisong input").click(function(){
    var goodsMoney = parseFloat(<{$goodsMoney}>);
    var free = parseFloat($(this).attr('data-free'));
    var money = parseFloat($(this).attr('data-money'));
    if (goodsMoney >= free){
      $("#yunfei").html('0');  
      $("#totalMoney").html(goodsMoney.toFixed(2));    
      $("#money").val(goodsMoney); 
      $("#paymentMoney").val(0);
    }else{
      $("#yunfei").html(money.toFixed(2));
      $("#totalMoney").html((goodsMoney+money).toFixed(2)); 
      $("#money").val(goodsMoney+money); 
      $("#paymentMoney").val(money);
    }
      
  });
})

function checkOrder(){
  if ($('#address').val()==""){
    _alert("请选择收货地址");
    return false;
  }

  /*var val=$('input:radio[name="payment"]:checked').val();
  if(val==null){
      _alert("请选择配送方式");
      return false;
  }*/

  var val=$('input:radio[name="payType"]:checked').val();
  if(val==null){
      _alert("请选择支付方式");
      return false;
  }

  return true;
}
</script>